<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .list {
            width: 500px;
            display: flex;
            height: 200px;
            justify-content: space-around;
            margin: 0 auto;
        }
        
        .list li {
            list-style: none;
            flex: 1;
            height: 200px;
            line-height: 200px;
            text-align: center;
            background: skyblue;
            cursor: pointer;
        }
        
        .list .active {
            background: palevioletred;
            color: white;
        }
    </style>
</head>

<body>
    <div id="app">
        <ul class="list">
            <li :class="index==activeIndex?'active':''" v-for="(item,index) in navlist" @click="change(index,item.name)" :key="index">{{item.name}}</li>
        </ul>
        <h1>你当前选择了：{{selectItem}}</h1>
    </div>
    <script src="./vue.js"></script>
    <script>
        new Vue({
            el: "#app",
            data() {
                return {
                    selectItem: "", //当前选择的文字
                    activeIndex: 0, //当前激活的下标
                    navlist: [{
                        name: "首页",
                        to: "/home"
                    }, {
                        name: "国际",
                        to: "/inter"
                    }, {
                        name: "国内",
                        to: '/china'
                    }, {
                        name: "游戏",
                        to: "/game"
                    }]
                }
            },
            methods: {
                change(index, name) { //点击li 改变当前激活下标
                    this.activeIndex = index;
                    this.selectItem = name;
                }
            },
        })
    </script>
</body>

</html>